package com.breeze.components.core.util.json.serializer;

import cn.hutool.core.util.DesensitizedUtil;
import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;

/**
 * 前三位，后4位，其他隐藏，比如135****2210
 *
 * @author breeze
 */
public class PhoneStringSerializer extends JsonSerializer<String> {
  @Override
  public void serialize(String value, JsonGenerator gen, SerializerProvider serializers)
      throws IOException {

    if (StrUtil.isNotEmpty(value)) {
      gen.writeString(DesensitizedUtil.mobilePhone(value));
      return;
    }
    gen.writeString(value);
  }
}
